//倒计时对象
let time = 60;

function waitingTime(btn) {
    if (time === 0) {
        btn.disabled = false;
        btn.value = "重新获取验证码";
        time = 60;
        return;
    } else {
        btn.value = time + "秒后重新获取";
        time--;
    }
    setTimeout(function () {
        waitingTime(btn)
    }, 1000);
}

function isEmail(s) {
    return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s);
}

function getVerifyCode(thisBtn) {
    var email = $("#your-email").val();

    if (!email) {
        alert("请先填写您的邮箱！");
    } else {
        if (!isEmail(email)) {
            alert("请输入正确的邮箱!")
        } else {
            //禁用点击事件
            $.ajax(CONTEXT_PATH + "/forget/code",{
                method: 'POST',
                data: {email: email},
                success: function (result) {
                    // console.log(result);
                    result = $.parseJSON(result);
                    //严格相等运算符
                    if (result.code === 0) {
                        alert("验证码已发送至您的邮箱,请登录邮箱查看!");
                    } else {
                        alert(result.msg);
                    }
                },
                error: function () {
                    alert("验证码发送失败!");
                }
            });
            thisBtn.disabled = true;
            waitingTime(thisBtn);
        }
    }

}